<?php

if(!defined('DEDEINC')) exit('Request Error!');


class Cod
{
	var $mid;
    var $return_url = "/payback/recharge.php?dopost=cod";
	
    function Cod()
    {
		global $dsql;
		$this->dsql = $dsql;
    }

    function __construct()
    {
        $this->Cod();
    }
	
	function SetReturnUrl($returnurl='')
    {
        if (!empty($returnurl))
        {
            $this->return_url = $returnurl;
        }
    }

    function GetCode($order)
    {	  
		//print_r($order);
		$buyid=$order['buyid'];
		$payment_type=$order['payment_type'];
		//exit;
		$row = $this->dsql->GetOne("SELECT * FROM #@__member_operation WHERE buyid = '$buyid'");
		$member = $this->dsql->GetOne("SELECT * FROM #@__member WHERE mid = '$row[mid]'");	
		$smoney=$member['money']-$row['money'];
		$surmoney=$member['money']-$row['surplus'];		
		if($smoney<0){	
		 ShowMsg("您的金币不足，请充值后操作或选择其他支付方式",'-1');
		exit;
		}elseif($surmoney<0 && $payment_type=='2' ){
		 ShowMsg("您的金币不足，请充值后操作或选择其他支付方式",'-1');
		 exit;
		}else{
		header("Location: /payback/recharge.php?dopost=return&code=cod&out_trade_no=$buyid&payment_type=$payment_type"); 
		exit;
		}
    }

}